#include "stdafx.h"

#include "../../NSNetLibSrc/Framework/ServerFramework/ServerProcessBase.h"
#include "../../NSNetLibSrc/Framework/ServerFramework/ServerFramework_Architecture.h"
#include "../../NSNetLibSrc/Framework/ServerFramework/ServerFTPMgr.h"
#include "../../NSNetLibSrc/Framework/ServerFramework/ServerFramework_Security.h"
#include "../../NSNetLibSrc/Framework/ServerFramework/ServerFramework_Database.h"

#include "../../NSNetLibSrc/Include/NetFramework_MsgDef.h"

#include "ServiceManagerProcess.h"
#include "ServiceManager_MsgDef.h"
#include "ServiceManager_OverlapJob.h"
#include "ContentUserManager.h"
#include "SMC_LOG_TYPE.h"
#include "SMC_MSG_DEF.h"

//-------------------------------------------------------------------------------------------------
void CServiceManagerProcess::WriteLog(std::wstring& szUserID, BYTE btCatagory, std::wstring& szLog)
{
	COverlapJob_SMLog* pOverlapJob = COverlapJob_SMLog::NewItem();
	pOverlapJob->Init( m_pTask, szUserID, btCatagory, szLog.c_str());

	CServerProcessBase* pProcessBase = (CServerProcessBase*)m_pTask->GetServiceObject();
	pProcessBase->ProcessLocalOverlapJob( pOverlapJob);	
}

void CServiceManagerProcess::WriteLog(DWORD dwSessionID, BYTE btCatagory, std::wstring& szLog)
{
	sServiceManagerUser* pUser = FindUser( dwSessionID);
	if(!pUser) return;
	
	COverlapJob_SMLog* pOverlapJob = COverlapJob_SMLog::NewItem();
	pOverlapJob->Init( m_pTask, pUser->m_szUser, btCatagory, szLog.c_str());

	CServerProcessBase* pProcessBase = (CServerProcessBase*)m_pTask->GetServiceObject();
	pProcessBase->ProcessLocalOverlapJob( pOverlapJob);
}

void CServiceManagerProcess::WriteLog(DWORD dwSessionID, BYTE btCatagory, LPCWSTR format, ...)
{
	WCHAR buff[ MAX_PATH];
	
	va_list va;
	va_start( va, format);
	if (SF_vsprintf( buff, MAX_PATH, format, va) != S_OK)
	{
		_ASSERT(FALSE);
	}
	va_end( va);

	WriteLog(dwSessionID, btCatagory, std::wstring(buff));
}

void CServiceManagerProcess::WriteLog(DWORD dwSessionID, LPCWSTR format,...)
{
	WCHAR buff[ MAX_PATH];
	
	va_list va;
	va_start( va, format);
	if (SF_vsprintf( buff, MAX_PATH, format, va) != S_OK)
	{
		_ASSERT(FALSE);
	}
	va_end( va);

	WriteLog(dwSessionID, 0xff, std::wstring(buff));
}

BYTE CServiceManagerProcess::GetSMLogType(WORD wMsgID)
{
	switch(wMsgID)
	{
	case SMC_NOTICE_ACK:					return eLogBy_SR_Notice;
//	case SMC_QUERY_BLOCK_USER_ACK:			return eLogBy_SR_Notice;
	case SMC_QUERY_LOG_ACK:					return eLogBy_SR_UserLog;
	case SMC_QUERY_CHARDATA_ACK:			return eLogBy_SR_UserData;
	case SMC_QUERY_DAILY_STATISTICS_ACK:	return eLogBy_SR_UserData;
	case SMC_QUERY_USER_INFO_ACK:			return eLogBy_SR_UserData;
	case SMC_QUERY_EDIT_CHAR_ACK:			return eLogBy_SR_UserEdit;
	case SMC_QUERY_CHAR_ONLINE_STATUS_ACK:	return eLogBy_CAS;
	case SMC_QUERY_ONLINE_CHAR_JID_ACK:		return eLogBy_CAS;
	default: return 0xff;
	}
}
